# Maintainer: WeirdTreeThing <bradyn127@protonmail.com>
# Co-Maintainer: Jenneron <jenneron@protonmail.com>
pkgname=linux-postmarketos-mediatek-mt8183
pkgver=6.6.61
pkgrel=1
pkgdesc="Mainline kernel for mediatek mt8183"
arch="aarch64"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="
	bison
	devicepkg-dev
	findutils
	flex
	postmarketos-installkernel
	openssl-dev
	perl
	rsync
	gzip
	xz
	gmp-dev
	mpc1-dev
	mpfr-dev
	lz4
	zstd
"
replaces="linux-postmarketos-mtk-mt8183"

_carch="arm64"

# Source
_config="config-$_flavor.$CARCH"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac

source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	arm64-dts-mediatek-mt8183-Add-missing-GPU-clocks.patch
	arm64-dts-mediatek-mt8183-Add-video-encoder-decoder.patch
	arm64-dts-mediatek-mt8183-Drop-VDEC_SYS-register.patch
	arm64-dts-mediatek-mt8183-Add-register-names-and-sys.patch
	arm64-dts-mt8183-Add-jacuzzi-makomo-board.patch
	arm64-dts-mt8183-Add-jacuzzi-pico-pico6-board.patch
	arm64-dts-mt8183-Add-kukui-katsu-board.patch
	arm64-dts-mt8183-Add-kukui-jacuzzi-cerise-board.patch
	mt8183-kukui-jacuzzi-fix-display-resume.patch
	mt8183-kukui-jacuzzi-hack-dpms-resume.patch
	mt8183-fix-bluetooth.patch
	mt8183-kukui-jacuzzi-fennel14-rt1015p-sound.patch
	config-$_flavor.aarch64
"
builddir="$srcdir/linux-$_kernver"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}


sha512sums="
df3635ffdf68a2547eb3e992f4510bb5080bbeaea98731225f4d5e3c9afb532bc1f35f38321db49fb70ea0baec55b14f48b2251480c10432e8c428b2cc0a2028  linux-6.6.61.tar.xz
669a1bbf8707ec9294da83336673fbb55061a2eed0c6ddb2613da3ae4fa9b0e2bdbdd91ad166694173e3540ea934b2f3bf27d5f9659a6952de806765eed9b824  arm64-dts-mediatek-mt8183-Add-missing-GPU-clocks.patch
40246a8da036dc6c21592efd6625a4be22d6f524b067854f17f5671f5f3b134ed1c63a8c03a15a55e9b45b7d8d1a9b63833b86f38a6f5863e02cc8ddbf70fa57  arm64-dts-mediatek-mt8183-Add-video-encoder-decoder.patch
aee85972804ab4a254f007805e25d30a82bb87e48144a05805ccefd49f8530f588e2c50b6550f302895a675003ffbe8e7986c2214d76763474b88804fe7f1519  arm64-dts-mediatek-mt8183-Drop-VDEC_SYS-register.patch
567b13d7508fdf584a64bf3f9d71ba34c045c6e4610ef7f7024ed98f4e7ebbd78c0ee2d5dccc7a50e651e4a088c0621f5150d477520069965466d5db265160ab  arm64-dts-mediatek-mt8183-Add-register-names-and-sys.patch
c0ac0f26bb515a68b89515a19113a14e2cd11c940f01649a2e4e9261f852be66af6a53683fc3d4f2ae7b1289fa9247111772f458ff96e51742b2b1efc7a73a11  arm64-dts-mt8183-Add-jacuzzi-makomo-board.patch
5a1bdadc6cb12c1fb52c1ed8710e0d0c05e91b4559725fe7b26c41bc6fa375800cbb51e554401cdf419fbfdf6ab7f91f1efb5ad333db2e0e0466036f41eff519  arm64-dts-mt8183-Add-jacuzzi-pico-pico6-board.patch
69f26a25a9a35eaf8f0c655e3f50a5ab19a5f727b1cdf49ad0c9cb89c69cd9517bd381a62e5197c1f00a7c2f03cd2411415f455e9fb5a2c8c1afa777e754398e  arm64-dts-mt8183-Add-kukui-katsu-board.patch
a95ce4a71d249ef401ca04cf8faf85b9022114d35fef5a0ce18929f734a0ac80ed0332648cc9768625f3c26b3720679e1a20bf8ac564087bd4c64f49cd96cc45  arm64-dts-mt8183-Add-kukui-jacuzzi-cerise-board.patch
519b6468bca78d0e315c826592ae40dddca9daeba7c2b451a20ca996494cca45721833b9138fefbb543f53e0b9257c78ec4fec54de2a160aa8df730daf3ac996  mt8183-kukui-jacuzzi-fix-display-resume.patch
e9a128a8ddd98c6c8957ba45186afa2ea8ebeac83d4f2db3ff9ee8a5dd8027af90868c334a7b456bfe7dce793517f27ad63efa220bc933e3407f6362da6d7b2a  mt8183-kukui-jacuzzi-hack-dpms-resume.patch
d74da1231181835bec82015da1b3f5b08a1fe9c3c35dd712e285891094d94d9427ceac75d32f74be3a635e17d93ad82b37adf97db8176efc91aed17535023fc2  mt8183-fix-bluetooth.patch
9b8707de42635734031495da055c5860addeb656051540f1a14404b10aa8b501168d8b0e274b37bce989db3bc050e9beef722189556f6d782b92cc907731488d  mt8183-kukui-jacuzzi-fennel14-rt1015p-sound.patch
e2846d9251b3fd610fb4f4889601e49ea848d28dbd1f4d8a24c049ac8dd1e3a3ecd7374948501f7a8cc0b15e9e095f94e2ceaaac68f3f1610fb192096a53b506  config-postmarketos-mediatek-mt8183.aarch64
"
